package me.pinion.controller.route;

import com.jfinal.config.Routes;
import com.jfinal.core.Controller;
import me.pinion.controller.annotation.RouteBind;
import me.pinion.kit.ClassCatch;
import me.pinion.kit.ClassKit;


public class AutoRoutes extends Routes{
    @Override
    public void config() {
        ClassKit.loopClasses(new ClassCatch() {
            @Override
            public void doCatch(Class<?> clazz) {
                if (Controller.class.isAssignableFrom(clazz)){
                    RouteBind bind = clazz.getAnnotation(RouteBind.class);
                    if (bind != null){
                        AutoRoutes.this.add(bind.value(), (Class<? extends Controller>) clazz);
                    }
                }
            }
        });
    }
}
